package com.meilai.project.controller.web.personal.handle;

import com.meilai.project.dto.CommonResult;
import com.meilai.project.service.personal.handle.PersonalHandleService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/web/personal_handle")
public class PersonalHandleController {
    @Autowired
    private PersonalHandleService service;

    @GetMapping("to_check_list")
    @ApiOperation(value = "待审核列表")
    public CommonResult toCheckList(@RequestParam(name = "page", defaultValue = "1") Integer page,
                                    @RequestParam(name = "page_size", defaultValue = "10") Integer page_size) {
        return new CommonResult().success(service.getToCheckList(page, page_size, true));
    }

    @GetMapping("processing_list")
    @ApiOperation(value = "流程中列表")
    public CommonResult processingList(@RequestParam(name = "page", defaultValue = "1") Integer page,
                                       @RequestParam(name = "page_size", defaultValue = "10") Integer page_size) {
        return new CommonResult().success(service.getProcessingList(page, page_size, true));
    }

    @GetMapping("finished_list")
    @ApiOperation(value = "已通过列表")
    public CommonResult finishedList(@RequestParam(name = "page", defaultValue = "1") Integer page,
                                     @RequestParam(name = "page_size", defaultValue = "10") Integer page_size) {
        return new CommonResult().success(service.getFinishedList(page, page_size, true));
    }

    @GetMapping("back_list")
    @ApiOperation(value = "被退回列表")
    public CommonResult backList(@RequestParam(name = "page", defaultValue = "1") Integer page,
                                 @RequestParam(name = "page_size", defaultValue = "10") Integer page_size) {
        return new CommonResult().success(service.getBackList(page, page_size, true));
    }

    @GetMapping("draft_list")
    @ApiOperation(value = "草稿箱列表")
    public CommonResult draftList(@RequestParam(name = "page", defaultValue = "1") Integer page,
                                  @RequestParam(name = "page_size", defaultValue = "10") Integer page_size) {
        return new CommonResult().success(service.getDraftList(page, page_size, true));
    }

    @GetMapping("delete_list")
    @ApiOperation(value = "已删除列表")
    public CommonResult deleteList(@RequestParam(name = "page", defaultValue = "1") Integer page,
                                   @RequestParam(name = "page_size", defaultValue = "10") Integer page_size) {
        return new CommonResult().success(service.getDeleteList(page, page_size, true));
    }

    @GetMapping("checked_list")
    @ApiOperation(value = "审核历史列表")
    public CommonResult checkedList(@RequestParam(name = "page", defaultValue = "1") Integer page,
                                    @RequestParam(name = "page_size", defaultValue = "10") Integer page_size) {
        return new CommonResult().success(service.getCheckedList(page, page_size, true));
    }

    @GetMapping("check_history")
    @ApiOperation(value = "审批记录拉取")
    public CommonResult checkHistory(@RequestParam(name = "wf_data_id", required = true) Long wf_data_id,
                                     @RequestParam(name = "data_id", required = true) Long data_id) {
        return new CommonResult().success(service.getCheckHistory(wf_data_id, data_id));
    }

    @GetMapping("check_history2")
    @ApiOperation(value = "审批记录拉取2")
    public CommonResult checkHistory2(@RequestParam(name = "flow_type", required = true) Integer flow_type,
                                      @RequestParam(name = "data_id", required = true) Long data_id) {
        return new CommonResult().success(service.getCheckHistory2(flow_type, data_id));
    }

    @GetMapping("handle_counts")
    @ApiOperation(value = "待办提醒相关数量")
    public CommonResult getCounts() {
        return new CommonResult().success(service.getCounts());
    }
}
